<template>
  <div class="container">
    <el-dialog
        title="修改"
        :visible.sync="centerDialogVisible"
        width="30%"
        center>
      <el-form label-position="right" label-width="80px">
        <el-form-item label="用户编号">
          <el-input v-model="userInfo.code" disabled></el-input>
        </el-form-item>
        <el-form-item label="用户名称">
          <el-input v-model="userInfo.userName" disabled></el-input>
        </el-form-item>
        <el-form-item label="用户类型">
          <el-select v-model="userInfo.userType" placeholder="请选择用户类型">
            <el-option
                v-for="item in userTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户角色">
          <el-select v-model="userInfo.roleId" placeholder="请选择用户角色">
            <el-option
                v-for="item in userRoleList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="部门">
          <el-input v-model="userInfo.deptName" disabled></el-input>
        </el-form-item>
        <el-form-item label="电话号码">
          <el-input v-model="userInfo.phone" disabled></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="submitEdit">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>
import api from '@/utils/api';
import * as echarts from "echarts";
import axios from 'axios'
import data from "@/assets/data1.json";

export default {
  mounted() {
    this.getRoleList()
  },
  data() {
    return {
      centerDialogVisible: false,
      userInfo: {
        id: null,
        code: '',
        userName: '',
        userType: '',
        roleId: null,
        deptName: '',
        phone: ''
      },
      userTypeList: [
        {
          value: '超级管理员',
          label: '超级管理员'
        }, {
          value: '一般人员',
          label: '一般人员'
        }],
      userRoleList:[]
    }
  },
  methods: {
    open(row) {
      this.userInfo.id = row.id
      this.userInfo.roleId = row.roleId
      this.userInfo.code = row.code
      this.userInfo.userName = row.userName
      this.userInfo.deptName = row.deptName
      this.userInfo.userType = row.userType
      this.userInfo.phone = row.phone

      this.centerDialogVisible = true
    },
    clear() {
      this.userInfo.id = null
      this.userInfo.roleId = null
      this.userInfo.code = ''
      this.userInfo.userName = ''
      this.userInfo.deptName = ''
      this.userInfo.phone = ''
      this.userInfo.userType = ''
    },
    submitEdit() {
      const self = this
      const obj = {}
      obj.userType = this.userInfo.userType
      obj.roleId = this.userInfo.roleId
      obj.id = this.userInfo.id
      api.updateUser(obj).then((data) => {
        if (data.success == true) {
          self.$message({
            type: "success",
            message: "创建成功!",
          });
          self.centerDialogVisible = false;
          self.$emit("afterSubmit");
          self.clear()
        } else {
          self.$message.error(data.msg);
        }
      })
    },
    getRoleList() {
      api.roleSelectList()
          .then(res => {
            if (res.code == 200) {
                this.userRoleList = res.data
            }
          })
    }
  }
};
</script>
<style scoped>


</style>